function [ out ] = mat2data(file)
load_settings; 

disp(['Mat2Data: Loading mat file:' file]);
load(file);
%%
% Results struct type
field1 = 'cam_id'; value1 = 0;
field2 = 'day'; value2= 0;
field3 = 'hour'; value3 = 0;
field4 = 'ppl_rects'; value4 = [];
field5 = 'ppl_hogs'; value5 = [];
field6 = 'bg_rects'; value6 = [];
field7 = 'bg_hogs'; value7 = [];
field8 = 'set'; value8 = false;
field9 = 'hog_dims'; value9 = [];
field10 = 'filename'; value10 = '';

results = struct(field1, value1, field2, value2, field3, value3, field4, value4, field5, value5, field6, value6, field7, value7, field8, value8, field9, value9, field10, value10);

%% Inflate rects & change filenames
negRects = struct('r', [], 'fName', []);
posRects = struct('r', [], 'fName', []);
for ix = 1:length(negRECTS)
    negRects(ix).r = negRECTS{ix}.r ;
    negRects(ix).fName = regexprep(negRECTS{ix}.fName, '/Users/pless/data/webcam/', '/Users/Agata/Desktop/AMOS_Data/');
end
for ix = 1:length(posRECTS)
    posRects(ix).r = posRECTS{ix}.r;
    posRects(ix).fName = regexprep(posRECTS{ix}.fName, '/Users/pless/data/webcam/', '/Users/Agata/Desktop/AMOS_Data/');
end

%% Sort step
fields = fieldnames(posRects);
data_cell = struct2cell(posRects);
sz = size(data_cell);
data_cell = reshape(data_cell, sz(1), []);
data_cell = data_cell';
data_sortable = sortrows(data_cell, [2] ); % cam_id, day, hour
data_cell = reshape(data_sortable', sz);
posRects = cell2struct(data_cell, fields, 1);

fields = fieldnames(negRects);
data_cell = struct2cell(negRects);
sz = size(data_cell);
data_cell = reshape(data_cell, sz(1), []);
data_cell = data_cell';
data_sortable = sortrows(data_cell, [2] ); % cam_id, day, hour
data_cell = reshape(data_sortable', sz);
negRects = cell2struct(data_cell, fields, 1);

%% Append boxes
disp('Mat2Data: Appending');
prev = '';
ri = 0;
for ix = 1:length(negRects)
    if strcmp(negRects(ix).fName, prev)
        results(ri).bg_rects = [results(ri).bg_rects; negRects(ix).r];
        
    else
        ri = ri+1;
        name = regexp(negRects(ix).fName, '/', 'split');
        results(ri).cam_id = str2double(name{end-1});
        filename = name{end};
        time = regexp(filename(1:end-4), '_', 'split');
        results(ri).day = str2double(time{1});
        results(ri).hour = str2double(time{2});
        results(ri).filename = filename;
        results(ri).bg_rects = negRects(ix).r;
    end
    prev = negRects(ix).fName;
end

for ix = 1:length(posRects)
    name = regexp(posRects(ix).fName, '/', 'split');
    filename = name{6};
    for jx = 1:length(results)
        if strcmp(filename, results(jx).filename);
            results(jx).ppl_rects = [results(jx).ppl_rects; posRects(ix).r];
        end
    end
end
disp('Mat2Data: Done');
out=results;
end